/*
 * @Descripttion:
 * @version:
 * @Author: Connor
 * @Date: 2020-10-22 10:50:52
 * @LastEditors: Sam
 * @LastEditTime: 2021-07-08 18:42:52
 */
import * as constant from '@/store/yg/common/constant'
import { ajax } from '@/store/yg/common/utils'
import { m } from "@/store/yg/common/local";
import { Message, Loading } from 'element-ui'

export function exportExcel (fn, queryParam, ids) {
  let loadingInstance = Loading.service();
  if (ids.length > 0) {
    queryParam["ids"] = ids;
  } else {
    queryParam["ids"] = null;
  }
  //console.log("fn",fn,queryParam);
  ajax(fn, queryParam, { q: '-' }).then(res => {
    //console.log("exportUrl",res);
    loadingInstance.close();
    if (res.path) {
      var path = path = constant.FILE_SERVER + res.path;
      //location.href = constant.API_SERVER + '/open/downloadFileByHttp?fileName='+res.fileName+'&path='+path;
      window.open(constant.API_SERVER + '/open/downloadFileByHttp?fileName=' + res.fileName + '&path=' + path);
    } else if (res.errorMesage) {
      Message.error(m(res.errorMesage));

    } else {
      Message.error('error');
    }



  })

}
